﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Chess.Common
{
    [Serializable]
    public abstract class Package
    {
        public PackageType PackageType;
        public string UserName { get; private set; }

        public Package(PackageType packageType, string userName)
        {
            PackageType = packageType;
            UserName = userName;
        }
    }

    [Serializable]
    public class RegistrationRequestPackage : Package
    {
        public RegistrationRequestPackage(string userName, string passwordHash)
            : base(PackageType.RegistrationRequest, userName)
        {
            PasswordHash = passwordHash;
        }

        public string PasswordHash { get; private set; }
    }

    [Serializable]
    public class ChessMovePackage : Package
    {
        public ChessMovePackage(string userName, string userTo, BytePoint from, BytePoint to)
            : base(PackageType.ChessMove, userName)
        {
            UserTo = userTo;
            From = from;
            To = to;
        }

        public string UserTo { get; private set; }
        public BytePoint From { get; private set; }
        public BytePoint To { get; private set; }
    }

    [Serializable]
    public class SuggestGamePackage : Package
    {
        public SuggestGamePackage(string userName, string toUser)
            : base(PackageType.SuggestGame, userName)
        {
            ToUser = toUser;
        }

        public string ToUser { get; private set; }
    }

    [Serializable]
    public class SuggestGameAnswerPackage : Package
    {
        public SuggestGameAnswerPackage(string userName, string toUser, SuggestGameAnswerType answer)
            : base(PackageType.SuggestGameAnswer, userName)
        {
            Answer = answer;
            ToUser = toUser;
        }

        public SuggestGameAnswerType Answer { get; private set; }
        public string ToUser { get; private set; }
    }

    [Serializable]
    public class RegistrationAnswerPackage : Package
    {
        public RegistrationAnswerPackage(RegisterAnswerType answer)
            : base(PackageType.LoginAnswer, "Server")
        {
            Answer = answer;
        }

        public RegisterAnswerType Answer { get; private set; }
    }

    [Serializable]
    public class LoginRequestPackage : Package
    {
        public LoginRequestPackage(string userName, string passwordHash)
            : base(PackageType.LoginRequest, userName)
        {
            PasswordHash = passwordHash;
        }

        public string PasswordHash { get; private set; }
    }

    [Serializable]
    public class LogoutRequestPackage : Package
    {
        public LogoutRequestPackage(string userName)
            : base(PackageType.LogoutRequest, userName)
        {
        }
    }
    
    [Serializable]
    public class LoginAnswerPackage : Package
    {
        public LoginAnswerPackage(LoginAnswerType answer)
            : base(PackageType.LoginAnswer, "Server")
        {
            Answer = answer;
        }

        public LoginAnswerType Answer { get; private set; }
    }

    [Serializable]
    public class ClientsListPackage : Package
    {
        public ClientsListPackage(NetworkClientCollection clients)
            : base(PackageType.ClientsList, "Server")
        {
            ConnectedClients = clients;
        }

        public NetworkClientCollection ConnectedClients { get; private set; }
    }

    [Serializable]
    public class StartGamePackage : Package
    {
        public StartGamePackage(string userName)
            : base(PackageType.StartGame, userName)
        {
            //ClientId = clientId;
        }

        public int ClientId { get; private set; }
    }

    [Serializable]
    public class EndGamePackage : Package
    {
        public EndGamePackage(string userName)
            : base(PackageType.EndGame, userName)
        {
        }
    }

    [Serializable]
    public class ExitPackage : Package
    {
        public ExitPackage(string userName)
            : base(PackageType.Exit, userName)
        {
        }
    }

    [Serializable]
    public class MessagePackage : Package
    {
        public MessagePackage(string message, string userName)
            : base(PackageType.Message, userName)
        {
            Message = message;
        }

        public string Message { get; private set; }
    }

    [Serializable]
    public class ChangePositionPackage : Package
    {
        public ChangePositionPackage(PackageType packageType, string userName)
            : base(packageType, userName)
        {
        }
    }
}
